import { Animation, Component, _decorator } from 'cc';
import { OpenLoadModel_Ins } from './OpenLoadPanel';
import { autoComp, rootNode } from '../Manager/BaseManager';

const { ccclass, property } = _decorator;

@ccclass('TurningAni')
export class TurningAni extends Component {
  @autoComp(Animation, rootNode)
  anim: Animation;

  pauseEnable: boolean;
  // resumeEnable: boolean;

  protected onEnable(): void {
    this.anim.stop();
    this.anim.defaultClip = null;
    this.anim.play(this.anim.clips[0].name);
    this.pauseEnable = true;
  }

  protected onDisable(): void {}

  show(isShow) {
    if (this.node.active) return;
    this.node.active = isShow;
    // OpenLoadModel_Ins.basePanel.initPlayer();
  }

  /** 关闭 */
  close() {
    // OpenLoadModel_Ins.loadCallback && OpenLoadModel_Ins.loadCallback();
    if (this.pauseEnable) this.anim.pause();
  }

  resumeAni() {
    this.anim && this.anim.resume();
    this.pauseEnable = false;
  }

  /** 准备打开 */
  readyOpen() {}

  /** 结束 */
  finish() {
    // this.node.active = false;
    this.node.active = false;
    if (OpenLoadModel_Ins.basePanel?.node) OpenLoadModel_Ins.curPanel.node.active = false;
  }
}
